#ifndef RACE_H
#define RACE_H

#include "map.h"
#include "player.h"

#include "src/utils/logbuffer.h"
#include <BulletCollision/CollisionDispatch/btGhostObject.h>

using namespace std;

enum RaceStage
{
	COUNTDOWN = 0,
	RACE,
	FINISHED
};

class Race
{
	public:
		Race( Map* mmap, vector<string>* m_logbufferQueue, const Timer& t, std::vector<boost::shared_ptr<Player> >& mplayers, boost::shared_ptr<btDynamicsWorld> ownerWorld );
		~Race();

		boost::shared_ptr<btDynamicsWorld> m_ownerWorld;
		Map* map;
		std::vector<boost::shared_ptr<Player> >& players;
		int findPlayer(unsigned int id);
		void newMessageAllClients(const string& msg);
		void newLogMessage(const string& msg);

		int countdownTime;
		RaceStage racestage;
		unsigned short countdownCount;

		void resetTimer(const Timer& t);
// 		void startRace();
		void process( const Timer& t );
		int time_start;
		int time_elapsed;

	private:

		btPairCachingGhostObject* ghostObject;
		btManifoldArray manifoldArray;
		void checkFinish();

		vector<string>* logbufferQueue;
};
#endif
